<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>Student Address Book Project</title>
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div class="header-container">
		<div class="header">
			<div class="left">
				<a href="<c:url value="/" />"><div class="logo"></div></a>
			</div>
			<div class="right">
				<div class="user-navigation-area">
					Welcome <a href="<c:url value="/account" />">${username}</a> &nbsp|&nbsp <a href="<c:url value="/j_spring_security_logout" />" >Logout</a>
				</div>
			</div>
			<div class="clear"></div>
		</div><!-- END HEADER -->
	</div>
	<div class="content-container">
		<div class="admin-center-container">
			<form action="addUser.do" method="post">
			<table>
				<tbody>
					<c:if test="${message != null}">
						<p><c:out value="${message}"></c:out></p>
					</c:if>
					<tr>
						<td>Role: </td>
						<td>
							<select name="role">
								<option value="ROLE_USER">ROLE_USER</option>
								<option value="ROLE_ADMIN">ROLE_ADMIN</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>Username: </td>
						<td><input type="text" class="input-control" name="username" size="35"/></td>
					</tr>
					<tr>
						<td>Password: </td>
						<td><input type="password" class="input-control" name="password" size="35"/></td>
					</tr>
					<tr>
						<td>Confirm Password: </td>
						<td><input type="password" class="input-control" name="confpassword" size="35"/></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" class="stdbut" value="Add Account"/></td>
					</tr>
				</tbody>
			</table>
			</form>
		</div><!-- center container -->
		<div class="admin-result-list">
			<table class="div-tbl-content">
				<tbody>
					<tr>
						<td class="admin-tbl-header">USERNAME</td>
						<td class="admin-tbl-header">PASSWORD</td>
						<td class="admin-tbl-header">ROLE</td>
						<td class="admin-tbl-header">DELETE</td>
					</tr>
				<c:forEach items="${accounts}" var="account" varStatus="status">
					<c:choose>
						<c:when test="${status.count % 2 == 0}">
							<tr class="tbl-content-row-odd">
								<td class="admin-tbl-content-col"><c:out value="${account.username}"/></td>
								<td class="admin-tbl-content-col"><c:out value="${account.password}"/></td>
								<td class="admin-tbl-content-col">
								<c:set var="isAdmin" value="false"/>
									<c:forEach items="${account.roles}" var="role" varStatus="rolestatus">
										<c:if test="${rolestatus.count > 1}"> ;</c:if>
										<c:out value="${role.role}"></c:out>
										<c:if test="${role.role eq 'ROLE_ADMIN' }">
											<c:set var="isAdmin" value="true"/>
										</c:if>
									</c:forEach>
								</td>
								<td class="admin-tbl-content-col">
									<c:if test="${isAdmin != true}">
									<c:set var="link" value="deleteUser.do?idAccount=${account.idAccount}"></c:set>
										<button type="button" onclick="location.href='${link}'">Delete</button>
									</c:if>
								</td>
							</tr>
						</c:when>
						<c:otherwise>
							<tr class="tbl-content-row">
								<td class="admin-tbl-content-col"><c:out value="${account.username}"/></td>
								<td class="admin-tbl-content-col"><c:out value="${account.password}"/></td>
								<td class="admin-tbl-content-col">
								<c:set var="isAdmin" value="false"/>
									<c:forEach items="${account.roles}" var="role" varStatus="rolestatus">
										<c:if test="${rolestatus.count > 1}">; </c:if>
										<c:out value="${role.role}"></c:out>
										<c:if test="${role.role eq 'ROLE_ADMIN' }">
											<c:set var="isAdmin" value="true"/>
										</c:if>
									</c:forEach>
								</td>
								<td class="admin-tbl-content-col">
									<c:if test="${isAdmin != true}">
									<c:set var="link" value="deleteUser.do?idAccount=${account.idAccount}"></c:set>
										<button type="button" onclick="location.href='${link}'">Delete</button>
									</c:if>
								</td>
							</tr>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				</tbody>
			</table>
		</div>
	</div>      
</body>
</html>